<?php


namespace App\Logic\doctor;


use App\Http\Controllers\Controller;
use App\Models\Doctor;
use App\Server\ApiService;

class DoctorLogic extends Controller
{
    public static function doctorList()
    {
        $data = Doctor::paginate(10);
        if ($data)
        {
            return ApiService::success('医生列表获取成功',$data);
        } else {
            return ApiService::fail('医生列表获取失败');
        }
    }

    /**
     * Name: 根据医生名称和医生类别多条件搜索医生
     * User: 王梓墨
     * Date: 2023/6/19
     * Time:15:05
     * @param $params
     * @return \Illuminate\Http\JsonResponse
     */
    public static function searchDoctor($params)
    {
        //医师姓名
        $name = $params['name'];
        //医师类别
        $typeName = $params['type_name'];
        $where = [];
        if (isset($name) || !empty($name))
        {
            $where[] = ['name','like',"%$name%"];
        }
        if (isset($typeName) || !empty($typeName))
        {
            $where[] = ['type_name','like',"%$typeName%"];
        }
        $data = Doctor::where($where)->get();
        if ($data)
        {
            return ApiService::success('搜索医师成功',$data);
        } else {
            return ApiService::fail('搜索医师失败');
        }
    }
}
